package com.zzy.edu.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzy.commonutils.R;
import com.zzy.edu.entity.EduComment;
import com.zzy.edu.entity.vo.comment.CommentVo;
import com.zzy.edu.service.EduCommentService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author KAZU
 * @since 2023-01-22
 */
@RestController
@RequestMapping("/eduservice/comment")
@CrossOrigin
public class EduCommentController {
	
	@Autowired
	private EduCommentService commentService;
	
	/**
	 * 评论分页功能
	 * */
	@GetMapping("{courseId}/{page}/{limit}")
	@ApiOperation(value = "评论分页功能")
	public R getPageList(@ApiParam(name = "page", value = "当前页码", required = true)
				   @PathVariable Long page,
				   @ApiParam(name = "limit", value = "每页记录数", required = true)
				   @PathVariable Long limit,
				   @ApiParam(name = "courseId", value = "对应课程id", required = true)
				   @PathVariable String courseId) {
		Page<EduComment> commentPage = new Page<>(page, limit);
		Map<String, Object> map = commentService.getPageList(commentPage, courseId);
		return R.ok().data(map);
	}
	
	/**
	 * 添加评论
	 * */
	@PostMapping("save")
	public R addComment(@RequestBody CommentVo commentVo) {
		EduComment eduComment = new EduComment();
		BeanUtils.copyProperties(commentVo, eduComment);
		boolean save = commentService.save(eduComment);
		if (save) {
			return R.ok();
		} else {
			return R.error();
		}
		
	}


	
	
}











